package elektra.plugin.core;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Nullable;

import com.google.common.base.Function;
import com.google.common.base.Preconditions;

public class FunctionChain<T,E> implements Function<T,E>{
     private List<Function<T,E>> chain;
     public FunctionChain(){
    	 this.chain=new ArrayList<Function<T,E>>();
     }
     
	@Nullable
	public E apply(@Nullable T param) {

		E result=null;
	    
		for (Function<T,E> function: this.chain){
			result=function.apply(param);
		}
		
		return result;
		
	}
	
	public void addToChain(Function<T,E> function){
		Preconditions.checkNotNull(function);
		this.chain.add(function);
	}
	
	public void removeFromChain(Function<T,E> function){
		Preconditions.checkNotNull(function);
		this.chain.remove(function);
	}
     
     

}
